package com.mdd.service.refund.impl;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.request.AlipayTradeFastpayRefundQueryRequest;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
import com.alipay.api.response.AlipayTradeRefundResponse;
import lombok.extern.slf4j.Slf4j;
import com.mdd.service.refund.AlipayRefundService;
import com.mdd.validate.pay.RefundQuery;
import com.mdd.validate.pay.TradeRefundParams;
import org.springframework.stereotype.Service;

/**
 * 预授权退单
 * <p>
 * {@code @Description}
 * @Author 幻速
 * {@code @Date} 2023/10/30 19:48
 **/
@Slf4j
@Service
public class AlipayRefundServiceImpl implements AlipayRefundService {
    @Override
    public AlipayTradeFastpayRefundQueryResponse refundQuery(AlipayClient alipayClient, RefundQuery refundQuery) throws AlipayApiException {
        log.info("AlipayTradeFastpayRefundQueryRequest  params---->"+JSON.toJSONString(refundQuery));
        AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest();
        request.setBizContent(JSON.toJSONString(refundQuery));
        AlipayTradeFastpayRefundQueryResponse response = alipayClient.execute(request);
        log.info("AlipayTradeFastpayRefundQueryResponse----->"+JSON.toJSONString(response));
        return response;
    }

    @Override
    public AlipayTradeRefundResponse tradeRefund(AlipayClient alipayClient,TradeRefundParams tradeRefundParams) throws AlipayApiException {
        log.info("AlipayTradeRefundRequest  params---->"+JSON.toJSONString(tradeRefundParams));
        AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
        request.setBizContent(JSON.toJSONString(tradeRefundParams));
        AlipayTradeRefundResponse response = alipayClient.execute(request);
        log.info("AlipayTradeRefundResponse -------->"+response);
        return response;
    }
}
